package com.example.demo.msg.netty.Bytebuf;/**
 * Created by kete on 2018-10-17.
 */

import com.google.common.io.Files;
import com.google.common.io.Resources;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufProcessor;
import io.netty.buffer.Unpooled;
import io.netty.util.ByteProcessor;

import java.io.File;
import java.net.URL;
import java.nio.charset.Charset;

/**
 * 作者：kete
 * 创建时间：2018-10-17 11:26
 * 功能描述：
 * 版本：
 */
public class BytebufTest {

    public static void find(){
        String json = null;
        try {
            URL url = Resources.getResource("city.txt");
            File file = new File(url.getPath());
            if(file.exists()) {

                json = Files.toString(file, Charset.forName("UTF-8"));

            }
        } catch(IllegalArgumentException ex) {
            ex.printStackTrace();
        } catch(Exception ioex) {
            ioex.printStackTrace();
        }

        byte[] bytes = json.getBytes();

        ByteBuf byteBuf = Unpooled.buffer();

        byteBuf.writeBytes(bytes);

        int sb = byteBuf.forEachByte(ByteProcessor.FIND_CR);

        System.out.println("sb:"+sb);
    }

    public static void main(String[] args) {
        BytebufTest.find();
    }
}
